package com.erbao.dp.proxy.v04;

import java.util.Random;

interface Movable{
    void move();
}

class TankTimeProxy implements Movable {
    Tank tank;
    @Override
    public void move() {
        long start = System.currentTimeMillis();

        tank.move();

        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    public TankTimeProxy(Tank tank) {
        this.tank = tank;
    }
}

/**
 * @author CaoBaoYin
 * @since 2021/9/16 21:52
 */
public class Tank implements Movable {
    @Override
    public void move() {
        System.out.println("tank moving calalalala……");
        // 模拟坦克移动时间
        try {
            Thread.sleep(new Random().nextInt(10000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new TankTimeProxy(new Tank()).move();
    }
}
